<?php
/**
 * Description of model_follows
 *
 * @author Steffen Bilde
 */
class Model_follows extends CI_Model
{
    function  __construct()
    {
        parent::__construct();
    }

    //Create follow-row where $follower_id follows $following_id
    function follow($follower_id,$following_id)
    {
        $data = array(
                    'follower_id' => $follower_id,
                    'following_id' => $following_id);
        $this->db->insert('follows',$data);
    }


    //Delete follow-row where $follower_id follows $following_id
    function unfollow($follower_id,$following_id)
    {
        $this->db->where('follower_id', $follower_id);
        $this->db->where('following_id', $following_id);
        $this->db->delete('follows');
    }


    //Gets all following, where follower = $follower_id
    function get_following($follower_id)
    {
        $this->db->select('following_id');
        $this->db->where('follower_id',$follower_id);
        $Q = $this->db->get("follows");

        if ($Q->num_rows() > 0)
        {
          foreach ($Q->result() as $row)
          {
              $data[] = $row->following_id;
          }
        }
        else
        {
            $data = array();
        }
        $Q->free_result();
        return $data;
    }



}
?>